
import i18n from 'i18n-js';

import errorCode from './errorCode';
import logout from '../logout';
import ToastContainer from '../Toast';

async function checkError(code: number) {
  switch (code) {
    case errorCode.GIZ_SDK_TOKEN_INVALID:
    case errorCode.TOKEN_INVALID:
    case errorCode.GIZ_SDK_USER_NOT_LOGIN:
    case errorCode.TOKEN_INVALID_USER_NOT_EXIST:
    case errorCode.TOKEN_INVALID_TOKEN_EXPIRED: {
      console.log('SDK token 无效', code);
      logout();
      ToastContainer.error(i18n.t('LOGIN_EXPIRED'));
      break;
    }
    default: {
      break;
    }
  }
}

export default checkError;
